package cloud.maque.auth.controller;

import cloud.maque.auth.conf.AuthProperties;
import cloud.maque.auth.model.Oauth2User;
import cloud.maque.common.core.exceptions.BusinessException;
import cloud.maque.sso.client.annotations.TempToken;
import cn.dev33.satoken.temp.SaTempUtil;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class ViewController {

    @Autowired
    AuthProperties authProperties;

    @Autowired
    HttpSession httpSession;

    @RequestMapping("/")
    public String index(Model model) {

        model.addAttribute("gitee", authProperties.getGitee());
        model.addAttribute("giteeurl", authProperties.getGitee().GetFullUrl(authProperties.getGitee(), "0"));

        model.addAttribute("githubUrl", authProperties.getGithub().GetFullUrl(authProperties.getGithub(), "0"));

        model.addAttribute("userId", httpSession.getAttribute("userId"));
        model.addAttribute("userName", httpSession.getAttribute("userName"));
        model.addAttribute("accessToken", httpSession.getAttribute("accessToken"));
        return "index";
    }

    @RequestMapping("/bind")
    @TempToken
    public String BindUser(Model model, @RequestParam("token") String token) {

        //data 内容为：Oauth2User
        model.addAttribute("data", httpSession.getAttribute("data"));
        model.addAttribute("loginType", httpSession.getAttribute("loginType"));
        return "bind";
    }
}
